#include "stack_base_list.h"
#include <stdio.h>
#include <stdlib.h>
//创建节点
STACK_NODE *node_create(int data,STACK_NODE *next){
	STACK_NODE *node = malloc(sizeof(STACK_NODE));
	node -> data = data;
	node -> next = next;
	return node;
	}
//销毁节点
STACK_NODE *node_destory(STACK_NODE *node){
	STACK_NODE *next = node -> next;//记录节点值
	free(node);//node再用就是野指针
	//node = NULL;
	return next;
	}
//创建栈
STACK *stack_create(void){
	STACK *stack = malloc(sizeof(STACK));//代表申请栈的结构体的空间地址
	stack -> top = NULL;//赋null是为了后判断
	return stack;
	}
void stack_clear(STACK *stack){
	while(stack -> top){
	stack ->top = node_destory(stack -> top);
		}
	}
//销毁栈
void stack_destory(STACK *stack){
	//清空栈
	stack_clear(stack);
	free(stack);//
	}
//压栈
void stack_push(STACK *stack,int data){
	//1、申请节点并初始化，让该节点next指针指向老的栈顶
	//2、让top指针指向新的栈顶
	stack -> top = node_create(data,stack->top);
	}
//弹栈
int stack_pop(STACK *stack){
	int data = stack -> top -> data;
	//stack -> top = stack -> top -> next; 不能要 内存泄漏
	stack -> top = node_destory(stack -> top);
	return data;
	}
//判空 如果为空返回1 否则返回0
int stack_empty(STACK *stack){
	return !stack -> top;
	}
//判满 可能不需要
int stack_full(STACK *stack){
	return 0;
	}
//创建节点
